package com.chis.jxc;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wlj 处理文本：。。。
 * @version 2019年08月29日
 * @Description
 * @Company zwx
 */
public class DugeData {
    public static void main(String[] args) throws Exception {
        File file1 = new File("C:\\Users\\Administrator\\Desktop\\20190829\\bact.log");
        File file2 = new File("C:\\Users\\Administrator\\Desktop\\20190829\\data.log");
        FileReader m = null;
        FileWriter fileWriter = null;
        try {
            m = new FileReader(file1);
            fileWriter = new FileWriter(file2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        BufferedReader reader = new BufferedReader(m);
        String zone = null;
        String bact = null;
        while (true) {
            String nextline = null;
            nextline = reader.readLine();
            if (nextline != null && nextline.length() > 8) {
                if (nextline.startsWith("地区")) {
                    zone = nextline.substring(3);
                } else {
                    bact = nextline.substring(3, 17);
                    String[] strings = nextline.substring(22).split(",");
                    Map<String, List<String>> tmp = new HashMap<>();
                    for (String s : strings) {
                        List<String> l1 = new ArrayList<>();
                        if (tmp.containsKey(s.trim().toLowerCase())) {
                            l1 = tmp.get(s.trim().toLowerCase());
                        }
                        l1.add(s);
                        tmp.put(s.trim().toLowerCase(), l1);
                    }
                    for (String core : tmp.keySet()) {
                        List<String> l = tmp.get(core);
                        if (l.size() > 1) {
                            for (String s : l) {
                                if (!s.equals(core)) {
                                    fileWriter.append(zone).append(":").append(bact).append(":").append(s).append("\n");
                                }
                            }
                        }
                    }
                }
            }
            if (nextline == null) break;
        }
        reader.close();
        fileWriter.close();

    }
}
